#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[])
{
	if (argc < 2) 
	{
		printf("need a file name\n");
		return -1;
	}
	FILE * fh = fopen(argv[1], "r");
	if (fh == NULL)
	{
		printf("fopen fail\n");
		return -1;
	}
	int numWord = 0;
	int isWord = 0;
	int ch;
	while ((ch = fgetc(fh)) != EOF)
	{
		if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')))
		{
			if (isWord == 0) 
			{
				numWord ++;
			} 
			isWord = 1;
		}
		else
		{
			isWord = 0;
		}		
	}
	fclose(fh);
	printf("The file has %d words.\n", numWord);
	return 0;
}
